package com.corelib.rxAndRetrofit;

import com.corelib.Config;
import com.zhy.http.okhttp.OkHttpUtils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2016/12/27.
 */
public class RetrofitUtils {
    private static Retrofit.Builder singleton;
    public static APIService createAPIService(){
        getInstance();
        APIService service = singleton.build().create(APIService.class);
        return  service;
    };
    private static Retrofit.Builder getInstance(){
         synchronized (RetrofitUtils.class){
             if(singleton==null){
                 singleton = new Retrofit.Builder();
                 singleton.baseUrl(Config.baseurl);
                 singleton.client(OkHttpUtils.getInstance().getOkHttpClient());
                 singleton.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
                 singleton.addConverterFactory(GsonConverterFactory.create());
             }
             return singleton;
         }

    };
}
